﻿using System;
using System.Collections.Generic;
using UnityEngine;

public class USTimelineProperty : USTimelineBase
{
    [SerializeField]
    private List<USPropertyInfo> propertyList = new List<USPropertyInfo>();

    public void AddProperty(USPropertyInfo propertyInfo)
    {
        if (((propertyInfo.propertyName == null) || !this.ContainsProperty(propertyInfo.propertyName, propertyInfo.component)) && ((propertyInfo.fieldName == null) || !this.ContainsProperty(propertyInfo.fieldName, propertyInfo.component)))
        {
            this.propertyList.Add(propertyInfo);
        }
    }

    public bool ContainsProperty(string propertyName, Component component)
    {
        foreach (USPropertyInfo info in this.propertyList)
        {
            if ((info != null) && ((info.component == component) && ((info.propertyName == propertyName) || (info.fieldName == propertyName))))
            {
                return true;
            }
        }
        return false;
    }

    public USPropertyInfo GetProperty(string propertyName, Component component)
    {
        foreach (USPropertyInfo info in this.propertyList)
        {
            if ((info != null) && ((info.component == component) && ((info.propertyName == propertyName) || (info.fieldName == propertyName))))
            {
                return info;
            }
        }
        return null;
    }

    public bool HasPropertiesForComponent(Component component)
    {
        foreach (USPropertyInfo info in this.propertyList)
        {
            if (component == info.component)
            {
                return true;
            }
        }
        return false;
    }

    public override void Process(float sequencerTime)
    {
        foreach (USPropertyInfo info in this.propertyList)
        {
            if (info != null)
            {
                info.SetValue(sequencerTime);
            }
        }
    }

    public void RemoveProperty(USPropertyInfo propertyInfo)
    {
        this.propertyList.Remove(propertyInfo);
    }

    public override void Reset()
    {
        foreach (USPropertyInfo info in this.propertyList)
        {
            if (info != null)
            {
                info.SetValue(0f);
            }
        }
    }

    public List<USPropertyInfo> Properties
    {
        get
        {
            return this.propertyList;
        }
    }
}

